package Other.Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-10-23
 * Time: 18:16
 */
public class ThreadWork_10_15 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            int i = 10;
            while(i > 0){
                synchronized (Integer.class){
                    try {
                        Integer.class.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("A");
                i--;
                synchronized (Object.class){
                    Object.class.notify();
                }
            }
        });

        Thread thread2 = new Thread(() -> {
            int i = 10;
            while(i > 0){
                synchronized (Object.class){
                    try {
                        Object.class.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println("B");
                i--;
                synchronized (String.class){
                    String.class.notify();
                }
            }
        });

        Thread thread3 = new Thread(() -> {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            int i = 10;
            while(i > 0){
                synchronized (Integer.class){
                    Integer.class.notify();
                }
                System.out.println("C");
                i--;
            }
        });

        thread1.start();
        thread2.start();
        thread3.start();

        thread1.join();
        thread2.join();
        thread3.join();
    }
}
